package com.jax.pronet.web.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jax.pronet.bo.Network;
import com.jax.pronet.bo.Programmer;
import com.jax.pronet.xml.NetworkLoader;

public class PronetServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
      
    // Use "request" to read incoming HTTP headers (e.g. cookies)
    // and HTML form data (e.g. data the user entered and submitted)
    
    // Use "response" to specify the HTTP response line and headers
    // (e.g. specifying the content type, setting cookies).
    
    PrintWriter out = response.getWriter();
    // Use "out" to send content to browser
    NetworkLoader networkLoader = new NetworkLoader();
    
    Network network = networkLoader.loadNetwork();
    List<Programmer> programmerList = network.getListOfProgrammers();
    
    out.println("<!DOCTYPE html> <html> <body>");
    out.println("<table border=\"0\">");
    out.println("<tr>" +
    		"<th>Programmer</th>" +
    		"<th>Skills</th>" +
    		"<th>Recommendations</th>" +
    		"</tr>");
    for (Programmer programmer : programmerList) {
    	out.println("<tr>" );
    	out.println("<td width=\"33%\">" + programmer.getName() + "</td>" );
    	out.println(		"<td width=\"33%\">");
    	
    	for (int j=0; j<programmer.getListOfSkills().size(); j++) {
    		out.println(programmer.getListOfSkills().get(j));
    		if(j<programmer.getListOfSkills().size()-1) {
    			out.println(",");
    		}
    		
    	}
    	out.println("</td>" );
    	out.println(		"<td width=\"33%\">");
    	for (int i=0; i<programmer.getListOfRecommendations().size(); i++) {
    		out.println(programmer.getListOfRecommendations().get(i));
    		if(i<programmer.getListOfRecommendations().size()-1) {
    			out.println(",");
    		}
    	}
    	out.println("</td>" );
    	out.println("</tr>");
    }
    out.println("</table>");
    out.println("<p>");
    out.println("<p>");
    out.println("<p>");
    out.println("\n\n<a href=\"http://localhost:8080/pronet-base/index.html\">Home</a>");
	out.println("</body>" + "</html>");
  }
}